package com.jay.io.clazz;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class BufferedStreamCls {
	public static void main(String[] args) {
		byte[] data = new byte[1];

		File srcFile = new File("pom.xml");
		File desFile = new File("pom.txt");

		try {
			BufferedInputStream bufferedInputStream = new BufferedInputStream(
					new FileInputStream(srcFile));
			BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(
					new FileOutputStream(desFile));

			System.out.println("复制文件: " + srcFile.length() + "字节");

			while (bufferedInputStream.read(data) != -1) {
				bufferedOutputStream.write(data);
			}

			// 将缓冲区中的数据全部写出
			bufferedOutputStream.flush();

			System.out.println("复制完成");

			// 显示输出pom.txt文件的内容
			bufferedInputStream = new BufferedInputStream(new FileInputStream(
					new File("pom.txt")));
			while (bufferedInputStream.read(data) != -1) {
				String str = new String(data);
				System.out.print(str);
			}

			bufferedInputStream.close();
			bufferedOutputStream.close();

		} catch (ArrayIndexOutOfBoundsException e) {
			System.out.println("using: java useFileStream src des");
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
